package com.va1m.mongodemo.controller;

import com.va1m.mongodemo.entity.User;
import com.va1m.mongodemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Admin
 */
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("/addUser")
    public User addUser(@RequestBody User user){
        return userService.addUser(user);
    }

    @PostMapping("/addUsers")
    public List<User> addUsers(@RequestBody List<User> users){
        return userService.addUsers(users);
    }

    @DeleteMapping("deleteUser")
    public void deleteUser(@RequestBody User user){
        userService.deleteUser(user);
    }

    @DeleteMapping("deleteUsers")
    public void deleteUsers(@RequestBody List<User> users){
        userService.deleteUsers(users);
    }

    @GetMapping("/getUserByName")
    public List<User> getUserByName(User user){
        return userService.findByName(user);
    }
}
